import pytest
import yaml
from faker import Faker


def pytest_collection_modifyitems(items):
    """
    处理中文的unicode显示问题
    :return:
    """
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")


# @pytest.fixture(autouse=True, scope='session')
def init_test_data():
    faker = Faker('zh_CN')
    data_structure = {'member_names': {'argnames': ['member_name', 'mobile_num'], 'argvalues': [], 'ids': []}}

    data = [[faker.name(), faker.phone_number()] for i in range(10)]
    data_structure['member_names']['argvalues'] = data
    data_structure['member_names']['ids'] = data
    print(data_structure)

    with open('./data/test.yaml', 'w', encoding='utf-8') as f:
        yaml.safe_dump(data_structure, f)

if __name__ == '__main__':
    init_test_data()